package org.edu.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;




import javax.servlet.http.HttpServletResponse;








import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.RequestAware;
import org.edu.service.DeptService;
import org.edu.service.TreeNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 主要用于测试
 * 
 * @author lenove-x
 * @version 1.1
 * 
 *          参与者：
 */

// 声明此类为控制层的类
@Controller
@ParentPackage("struts-default")

// 表示继承的父包
// 表示当前Action所在命名空间
public class HelloAction extends ActionSupport implements RequestAware {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Map<String, Object> request;
	@Autowired
	private TreeNodeService treeNodeService;
	@Autowired
	private DeptService deptService;
	private String id;
	private String name;
	
	//private Properties dbProp = new Properties();
	/**
	 * 主页的访问
	 */
	@Override
	@Action(value = "hello", results = { @Result(name = "success", location = "/index.jsp") })
	public String execute() throws Exception {
		
		System.out.println("路径："+ServletActionContext.getServletContext().getRealPath("/"));
		//deptService.updatatest();
		return SUCCESS;
	}
	@Action(value = "test", results = { @Result(name = "success", location = "/WEB-INF/jsp/helloword.jsp") })
	public String dotesturl(){
		return SUCCESS;
	}
	@Action(value = "jsontest")
	public void dojosn(){
		HttpServletResponse response=ServletActionContext.getResponse();  
        //以下代码从JSON.java中拷过来的  
        response.setContentType("text/html");  
        response.setCharacterEncoding("utf-8");
        PrintWriter out = null;  
        try {
			out = response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        //将要被返回到客户端的对象  
       // System.out.println(null==id?"null":id);//需要刷新的 节点id  父节点
//        out.println( "[{\'id\':1, \'pId\':0, \'name\':\'test1\'},{\'id\':11, \'pId\':1, \'name\':\'test11\'},{\'id\':111, \'pId\':11, \'name\':\'test111\'},{\'id\':2, \'pId\':0, \'name\':\'test2\'}]");
        out.println(treeNodeService.list(id).toString());
        out.flush();  
        out.close();
	}
	public Map<String, Object> getRequest() {
		return request;
	}
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	
}